package com.extension.company.view.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.extension.company.admin.R;
import com.extension.company.model.entity.CityNeedData;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者:zwk
 * 联系方式：497981239@qq.com
 * 时间：on 2019/4/13 09:27
 * 功能：城市需求的adapter
 */
public class CityNeedAdapter extends BaseRecyclerAdapter<CityNeedData, CityNeedAdapter.CityNeedHolder> {


	public CityNeedAdapter(Context context, List<CityNeedData> list) {
		super(context, list);
	}

	@Override
	public int getItemCount() {
		return super.getItemCount();
	}

	@Override
	public CityNeedHolder onCreateViewHolder(ViewGroup parent, int viewType) {
		View view = mInflater.inflate(R.layout.activity_cityneed_rv_item, null);
		return new CityNeedHolder(view);
	}

	@Override
	public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int position) {
		((CityNeedHolder) viewHolder).itemImg.setBackground(mContext.getResources().getDrawable(list.get(position).getImgPath()));
		((CityNeedHolder) viewHolder).itemTv.setText(list.get(position).getImgName());
		((CityNeedHolder) viewHolder).itemLL.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				click.itemClick(position);
			}
		});
		super.onBindViewHolder(viewHolder, position);
	}

	class CityNeedHolder extends RecyclerView.ViewHolder {

		@BindView(R.id.item_img)
		ImageView itemImg;
		@BindView(R.id.item_tv)
		TextView itemTv;
		@BindView(R.id.item_ll)
		LinearLayout itemLL;

		public CityNeedHolder(View itemView) {
			super(itemView);
			ButterKnife.bind(this, itemView);
		}
	}

	public interface recycleViewOnclick {
		void itemClick(int positon);
	}

	private recycleViewOnclick click;

	public void setRcyItemClick(recycleViewOnclick recycleViewOnclick) {
		this.click = recycleViewOnclick;
	}
}
